package tourist.springboot.service.impl;

import tourist.springboot.domain.Foods;
import tourist.springboot.domain.FoodsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tourist.springboot.service.FoodsService;

import java.util.List;

/**
 * Foods 业务层实现
 *
 * Created by bysocket on 30/09/2017.
 */
@Service
public class FoodsServiceImpl implements FoodsService {

    @Autowired
    FoodsRepository foodsRepository;

    @Override
    public List<Foods> findAll() {
        return foodsRepository.findAll();
    }

    @Override
    public List<Foods> findFoods(List<String> ids) {
        return foodsRepository.findAllById(ids);
    }

    @Override
    public Foods insert(Foods foods) {
        return foodsRepository.save(foods);
    }

    @Override
    public Foods update(Foods foods) {
        return foodsRepository.save(foods);
    }

    @Override
    public Foods delete(String id) {
        Foods foods = foodsRepository.findById(id).get();
        foodsRepository.delete(foods);
        return foods;
    }

    @Override
    public Foods findById(String id) {
        return foodsRepository.findById(id).get();
    }
}
